package com.zrrd.springboot_first.controller;

import com.zrrd.springboot_first.pojo.Student;
import com.zrrd.springboot_first.service.StudentService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author WanJl
 * @version 1.0
 * @title StudentController
 * @description
 * @create 2024/3/17
 */
@RestController
@RequestMapping("/pages/students")
public class StudentController {

    @Resource
    StudentService studentService;

    @GetMapping
    @ResponseBody
    public List<Student> queryAll(){
        System.out.println("controller--------->学生");
        return studentService.queryAll();
    }

    @GetMapping("/{id}")
    @ResponseBody
    public Student queryById(@PathVariable Integer id){
        return studentService.queryById(id);
    }

    @PostMapping
    @ResponseBody
    public Integer add(Student student){
        return studentService.insert(student);
    }


    @PutMapping
    @ResponseBody
    public Integer update(@RequestBody Student student){
        return studentService.update(student);
    }

    @DeleteMapping("/{id}")
    @ResponseBody
    public Integer delete(@PathVariable Integer id){
        return studentService.delete(id);
    }












    //@Resource
    //StudentService studentService;

//    @Value("${mydataSource.driver}")
//    private String driver;
//
//    @Value("${mydataSource.url}")
//    private String url;
//    @Value("${mydataSource.username}")
//    private String username;
//    @Value("${mydataSource.password}")
//    private String password;

//    @GetMapping("/method")
//    @ResponseBody
//    public String method(){
//        return "hello springboot";
//    }
//
//    //增
//    @PostMapping
//    @ResponseBody
//    public String add(@RequestBody Student stduent){
//        return "添加成功";
//    }
//
//    //删
//    @DeleteMapping("/{id}")
//    @ResponseBody
//    public String delete(@PathVariable Integer id){
//
//        return "删除成功";
//    }
//
//    //改
//    @PutMapping
//    @ResponseBody
//    public String update(@RequestBody Student stduent){
//        return "修改成功";
//    }
//
//    //查
//    @GetMapping
//    @ResponseBody
//    public String queryAll(){
////        System.out.println(driver);
////        System.out.println(url);
////        System.out.println(username);
////        System.out.println(password);
//        return "查询成功";
//    }
}
